﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Resources;
using System.Windows.Shapes;
using System.Xml.Linq;
using Sanctuary.Core.Images;
using Sanctuary.Core.Dialog;
using Sanctuary.Core.Audio;


namespace Sanctuary.Core
{
    public static class GameFile
    {
        private static StreamResourceInfo zipInfo;

        public static void Load(Stream zipStream, IImageControl imageControl, ITextControl textControl)
        {
            zipInfo = new StreamResourceInfo(zipStream, null);
            MainImageControls = imageControl;
            MainTextControl = textControl;

            GameBackgrounds = new Backgrounds(GetXDocument(Backgrounds.FILE_NAME), zipInfo);
            GameSounds = new Sounds(GetXDocument(Sounds.FILE_NAME), zipInfo);
            GameCharacters = new Characters(GetXDocument(Characters.FILE_NAME), zipInfo);
            GameDialog = new GameDialog(GetXDocument(GameDialog.FILE_NAME), zipInfo);
        }

        private static XDocument GetXDocument(string name)
        {
            StreamResourceInfo streamInfo = Application.GetResourceStream(zipInfo, new Uri(name, UriKind.Relative));
            Stream fileStream = streamInfo.Stream;
            return XDocument.Load(fileStream);
        }

        public static ITextControl MainTextControl { get; private set; }
        public static IImageControl MainImageControls { get; private set; }
        public static Backgrounds GameBackgrounds { get; private set;}
        public static Sounds GameSounds { get; private set; }
        public static Characters GameCharacters { get; private set; }
        public static GameDialog GameDialog { get; private set; }
    }
}
